<?php

namespace App\Models;



class Project extends Base
{

    protected $casts = [
        'tag_ids' => 'array',
        'target_user_ids' => 'array',
        'adv_map' => 'array',
    ];

    protected $appends = ['amount_show'];

    public function setTagIdsAttribute($value) {
        return $this->attributes['tag_ids'] = $value;
    }

    public function setTargetUserIdsAttribute($value) {
        return $this->attributes['target_user_ids'] = $value;
    }

    public function setAdvMapAttribute($value) {
        return $this->attributes['adv_map'] = $value;
    }

    public function category() {
        return $this->belongsTo(Category::class, 'category_id');
    }

    public function parent_category() {
        return $this->belongsTo(Category::class, 'parent_category_id');
    }

    public function getAmountShowAttribute() {
        return Config::getItem($this->amount);
    }

    public function getTagIdsShowAttribute() {
        $arr = [];
        foreach ($this->tag_ids as $id) {
            $arr[] = Config::getItem($id);
        }
        return $arr;
    }

    public function getTargetUserShowAttribute() {
        $arr = [];
        foreach ($this->target_user_ids as $id) {
            $arr[] = Config::getItem($id);
        }
        return $arr;
    }

    public function getManageModeShowAttribute() {
        return Config::getItem($this->manage_mode);
    }

    public function getCompanyTypeShowAttribute() {
        return Config::getItem($this->company_type);
    }

}
